package com.itheima.demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @SpringBootConfiguration  @Configuration 将当前类变成配置类
 * @EnableAutoConfiguration
 * @ComponentScan(excludeFilters = { @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
 * @Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })  扫描包，将bean注入到容器中
 */

//1.spring boot引导类上有一个注解 @EnableAutoConfiguration ，扫描所有jar包中 META/INF spring.factories,
// 加载@EnableAutoConfiguration key对应的value -> 所有配置类
    //2.根据配置类和方法上@Conditional条件注解判断是否需要加载
    //3.加载配置类过程中，读取配置文件@EnableConfigurationProperties将配置内容加载到配置类 @ConfigurationProperties声明前缀，将配置
    //注入到属性中
    //4.spring data redis默认使用的redis客户端是什么框架?
@SpringBootApplication
@RestController
public class DemoApplication {

    @Bean
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }


    public static void main(String[] args) {
        ConfigurableApplicationContext run = SpringApplication.run(DemoApplication.class, args);
//        Object redisTemplate = run.getBean("redisTemplate");
//        System.out.println(redisTemplate);
//        System.out.println(run.getBean("user"));

    }


    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/test")
    public String test2(){
       return "测试一下";
    }

    @GetMapping("/robot")
    public String test(String question){
        String forObject = restTemplate.getForObject("http://api.tianapi.com/txapi/robot/index?key=42fead4a396ecb0c220544ec240ba2e0&question=" + question, String.class);
        return forObject;
    }

    @GetMapping("/xuebeng")
    public String xuebeng(){
//        try {
//            Thread.sleep(2000L);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        System.out.println(Thread.currentThread().getName());
        return null;
    }
}
